﻿<Window
        x:Class="MusicExplorer.View.Popup.EntityPreferences"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="{Binding DisplayTitle}"
        Height="400" ResizeMode="NoResize" Width="500"
        xmlns:views="clr-namespace:MusicExplorer.View"
        >

    <Window.Resources>
        <ResourceDictionary>
            <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        </ResourceDictionary>
    </Window.Resources>
    
    <Grid Margin="5">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="30" />
        </Grid.RowDefinitions>

        <TabControl VerticalContentAlignment="Stretch" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch">
            <TabItem VerticalAlignment="Stretch" Header="{Binding ManagementTabTitle}">
                <Grid Margin="5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="200" />
                        <ColumnDefinition Width="40" />
                        <ColumnDefinition Width="200" />
                        <ColumnDefinition Width="40" />
                    </Grid.ColumnDefinitions>

                    <Grid.RowDefinitions>
                        <RowDefinition Height="20" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>

                    <TextBlock FontFamily="Helvetica" FontSize="14" VerticalAlignment="Center">
                        <TextBlock Text="Enabled" />
                        <TextBlock Text="{Binding EntityPluralName}" />
                    </TextBlock>

                    <ListBox ItemsSource="{Binding EnableEntities}" HorizontalAlignment="Stretch" SelectedItem="{Binding SelectedEnableEntity, Mode=TwoWay}" Grid.Row="1">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding DisplayName}" FontFamily="Helvetica" FontSize="14" VerticalAlignment="Center" />
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>

                    <Grid Grid.Column="1" Grid.Row="1" Margin="5, 0, 5, 0">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="4*" />
                            <RowDefinition Height="2*" />
                            <RowDefinition Height="4*" />
                        </Grid.RowDefinitions>
                        <Button Command="{Binding UpEntityCommand}" VerticalAlignment="Top">
                            <StackPanel>
                                <Image Source="../../Resources/Images/Icons/up.png" Width="16" Height="16" />
                            </StackPanel>
                        </Button>
                        <StackPanel Orientation="Vertical" Grid.Row="1">
                            <Button DockPanel.Dock="Bottom" VerticalAlignment="Bottom" Command="{Binding DisableEntityCommand}">
                                <StackPanel>
                                    <Image Source="../../Resources/Images/Icons/right.png" Width="16" Height="16"/>
                                </StackPanel>
                            </Button>
                            <Button DockPanel.Dock="Bottom" VerticalAlignment="Bottom" Command="{Binding EnableEntityCommand}">
                                <StackPanel>
                                    <Image Source="../../Resources/Images/Icons/left.png" Width="16" Height="16"/>
                                </StackPanel>
                            </Button>
                        </StackPanel>
                        <Button Grid.Row="2" VerticalAlignment="Bottom" Command="{Binding DownEntityCommand}">
                            <StackPanel>
                                <Image Source="../../Resources/Images/Icons/down.png" Width="16" Height="16"/>
                            </StackPanel>
                        </Button>
                    </Grid>

                    <TextBlock FontFamily="Helvetica" FontSize="14" VerticalAlignment="Center" Grid.Column="2">
                        <TextBlock Text="Disabled" />
                        <TextBlock Text="{Binding EntityPluralName}" />
                    </TextBlock>

                    <Grid Grid.Row="1" Grid.Column="2">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <ListBox ItemsSource="{Binding DisableEntities}" HorizontalAlignment="Stretch" SelectedItem="{Binding SelectedDisableEntity, Mode=TwoWay}"
                                 VerticalContentAlignment="Center" VerticalAlignment="Stretch">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding DisplayName}" Height="25" FontFamily="Helvetica" FontSize="14"/>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                        <Button Content="Delete" Grid.Row="1" Margin="0, 5, 0, 0" Command="{Binding RemoveEntityCommand}"
                                Visibility="{Binding CanAddEntity, Converter={StaticResource BooleanToVisibilityConverter}}" />
                    </Grid>
                </Grid>
            </TabItem>
            <TabItem Header="{Binding NewEntityTabTitle}" Visibility="{Binding CanAddEntity, Converter={StaticResource BooleanToVisibilityConverter}}">
                <Grid Margin="5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="30" />
                    </Grid.RowDefinitions>
    
                    <Grid Grid.ColumnSpan="2" Margin="0, 0, 0, 5">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <TextBox Margin="0, 0, 5, 0" Text="{Binding SearchTerms, UpdateSourceTrigger=PropertyChanged}" />
                        <Button Content="Search" Command="{Binding SearchEntityCommand}" Grid.Column="1" Margin="0, 0, 5, 0" />
                        <Button Grid.Column="2" HorizontalAlignment="Right" Command="{Binding AddEntityCommand}" Content="Add" />
                    </Grid>

                    <ListView Grid.Row="1" x:Name="entitiesListView" ItemsSource="{Binding SearchedEntitiesToAdd}" DisplayMemberPath="DisplayName"
                              VirtualizingPanel.IsVirtualizing="False" SelectedItem="{Binding SelectedEntityToAdd}" BorderThickness="1, 1, 1, 0">
                        <ListView.BorderBrush>
                            <SolidColorBrush>
                                <SolidColorBrush.Color>
                                    <Color A="255" R="187" G="187" B="187" />
                                </SolidColorBrush.Color>
                            </SolidColorBrush>
                        </ListView.BorderBrush>
                    </ListView>

                    <Border Grid.Row="2" BorderThickness="1, 0, 1, 1">
                        <Border.BorderBrush>
                            <SolidColorBrush>
                                <SolidColorBrush.Color>
                                    <Color A="255" R="187" G="187" B="187" />
                                </SolidColorBrush.Color>
                            </SolidColorBrush>
                        </Border.BorderBrush>
                        <views:Log DataContext="{Binding SearchedEntitiesLog}">
                        </views:Log>
                    </Border>
                </Grid>
            </TabItem>
        </TabControl>

        <Button Content="Accept" Grid.Row="1" HorizontalAlignment="Right" Width="100" Margin="0, 5, 0, 0" Click="Accept" />
    </Grid>
</Window>
